package mvc.enhancedElicoide;

import org.geom.Maths;
import org.geom.curve.Curve;
import org.geom.curve.helix.Elicoide;
import org.geom.curve.helix.EnhancedElicoide;
import org.render.Engine3D;

import mvc.elicoide.IModelElicoide;
import mvc.elicoide.ModelElicoide;
import mvc.model.ModelCurve;
import mvc.enhancedElicoide.ViewEnhanchedElicoide3D;

public class ModelComplexHelix extends ModelCurve implements IModelComplexHelix, IModelElicoide{

	private ModelCurve modelCurve;
	private ModelElicoide modelElicoide;

	//---------------------------------------------------------------------- constructor
	
	public ModelComplexHelix(ModelCurve curve, ModelElicoide elicoide) {
		super(new EnhancedElicoide(curve.getCurve(), (Elicoide)elicoide.getCurve()));
		this.modelCurve = curve;
		this.modelElicoide = elicoide;
		
		//con la propagazione verso il basso sarebbe:
		// super(new Enhanced(curve.getcurve, elicoide.getElicoide))
		
		initChilds();
	}

	private void initChilds() {
		modelCurve.addParent(this);
		modelElicoide.addParent(this);
		
		// TODO -   così è sbagliato: 
		//		    in realtà le modifiche dovrebbero 
		//			partire dalla curva più complessa
		//			e propagarsi verso il basso.
		//
		//			così: quando un controller vuole cambiare
		//			un parametro di una curva-componente
		//			usa il metodo delegato della curva complessa
		//			es: per cambiare il raggio dell'elica si usa ModelComplexHelix.setR
		//			e ModelComplexHelix.notifyAllView O ModelComplexHelix.setCurrentPoint
		//			chiama in delegazione tutti i notifyAllaView o setCurrentPoint 
		//			delle figlie!
	}
	
	//---------------------------------------------------------------------- getter && setter

	/* (non-Javadoc)
	 * @see mvc.enhancedElicoide.IEn#getElicoideModel()
	 */
	public ModelElicoide getElicoideModel() {
		// TODO Auto-generated method stub
		return modelElicoide;
	}

	/* (non-Javadoc)
	 * @see mvc.enhancedElicoide.IEn#getModelCurve()
	 */
	public ModelCurve getTrunkModel() {
		return modelCurve;
	}

	/* (non-Javadoc)
	 * @see mvc.enhancedElicoide.IEn#setModelCurve(mvc.model.ModelCurve)
	 */
	public void setModelCurve(ModelCurve modelCurve) {
		this.modelCurve = modelCurve;
		modelCurve.addParent(this);
	}

	@Override
	public float getK() {
		// TODO Auto-generated method stub
		return modelElicoide.getK();
	}

	@Override
	public float getR() {
		// TODO Auto-generated method stub
		return modelElicoide.getR();
	}

	@Override
	public void setK(float n) {
		modelElicoide.setK(n);
		this.notifyAllViews();
	}

	@Override
	public void setR(float n) {
		modelElicoide.setR(n);
		this.notifyAllViews();
	}

	@Override
	public float getU() {
		return ((EnhancedElicoide)curve).getParameterU();
	}


	@Override
	public void setU(float t) {
		((EnhancedElicoide)curve).setU(t, true);
	}

	@Override
	public void setU(float t, boolean increment) {
		((EnhancedElicoide)curve).setU(t, increment);
		
	}

	public ModelCurve getComplexHelix() {
		return this;
	}

	public float getLength() {
		return (float)Curve.length;
	}
	public void setLength(float n, boolean increment) {
		Curve.setLenght(n, increment);
	}
	
	public float getZoom() {
		return (float)Engine3D.getZoom();
	}
	public void setZoom(float n, boolean increment) {
		int intZoom = (int)Maths.mapProportion(n, 0, 100, 3780, 3680);
		if(increment) Engine3D.setZoom(Engine3D.getZoom()+intZoom);
		else Engine3D.setZoom(intZoom);
	}
	
	public void setTrunkVisibility(boolean n) {
		
		ViewEnhanchedElicoide3D.trunkVisibility = n;
	}
}
